//
//  EFTransHomeDetailViewCellMark.m
//  EnjogFood
//
//  Created by guocheng on 2017/7/27.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFTransHomeDetailViewCellMark.h"
#import "EFTransHomeDetailViewItemMark.h"

@interface EFTransHomeDetailViewCellMark()<UITextFieldDelegate>

@property(strong,nonatomic)UILabel* nameLabel;
@property(strong,nonatomic) UIView* lineView;

@end

@implementation EFTransHomeDetailViewCellMark


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

-(void)initView{
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.markTF];
    [self.contentView addSubview:self.lineView];
}

-(void)layoutSubviews{
    self.nameLabel.left = 20;
    self.nameLabel.top = 14;
    
    self.markTF.top = 11;
    
    self.lineView.left = 20;
    self.lineView.top = self.nameLabel.bottom + 14;
    
}

-(void)setObject:(EFTransHomeDetailViewItemMark *)item{
    [self.nameLabel setText:item.name];
    [self.nameLabel sizeToFit];
    self.nameLabel.top = 11;
    self.nameLabel.left = 20;
    self.markTF.left = self.nameLabel.right + 10;
    
    [self.markTF setText:item.mark];
    
}


-(UILabel*)nameLabel{
    if(_nameLabel == NULL){
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:13];
        _nameLabel.textColor = kBlack999;
    }
    return _nameLabel;
}

-(UITextField*)markTF{
    if(_markTF == NULL){
        _markTF = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 80,25)];
        _markTF.font = [UIFont systemFontOfSize:13];
        _markTF.textColor = kBlack999;
        _markTF.delegate = self;
    }
    return _markTF;
}


-(UIView*)lineView{
    if(_lineView == NULL){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 40, 1)];
        _lineView.backgroundColor = kBlackDDD;
        
    }
    return _lineView;
}


#pragma mark - UITextFieldDelegate

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField == self.markTF) {
        NSString *str = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if (str.length > 0) {
            if(self.markblock != nil){
                self.markblock(str);
            }
        }
        
    }
    return YES;
}




@end
